package com.duobaoyu.dby.supply.admin.controller.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.common.core.validator.groups.Add;
import com.duobaoyu.dby.common.core.validator.groups.Edit;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceDictionaryItemAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.DictionaryItemDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.DictionaryItemVO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.DictionaryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典项管理
 * @className: DictionaryItemController
 * @description: 字典项表
 * @author: lyy
 * @createDate: 2022-06-23 9:33
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/dictionary-item")
@Api(value = "dictionary-item", tags = "字典项表")
public class DictionaryItemController {

	private final ResourceDictionaryItemAdminClient resourceDictionaryItemAdminClient;

	/**
	 * 查询字典项列表
	 * @param dictionaryItem
	 * @return
	 */
	@GetMapping
	@ApiOperation(value = "查询字典项列表", notes = "查询字典项列表")
	@SupplySysLog(value = "查询字典项列表",operationType = OperationTypeEnum.SELECT)
	public R<Page<DictionaryItemVO>> queryPage(DictionaryItemDTO dictionaryItem) {

		return R.ok(resourceDictionaryItemAdminClient.queryPage(dictionaryItem));
	}

	/**
	 * 新增字典项表
	 * @param dictionaryItem
	 * @return
	 */
	@PostMapping
	@ApiOperation(value = "新增字典项表", notes = "新增字典项表")
	@SupplySysLog(value = "新增字典项表",operationType = OperationTypeEnum.INTERT)
	public R<Boolean> save(@RequestBody @Validated(value = Add.class) DictionaryItemDTO dictionaryItem) {

		return R.ok(resourceDictionaryItemAdminClient.createDictionaryItem(dictionaryItem));
	}

	/**
	 * 修改字典项表
	 * @param dictionaryItem
	 * @return
	 */
	@PutMapping
	@ApiOperation(value = "修改字典项表", notes = "修改字典项表")
	@SupplySysLog(value = "修改字典项表",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> modify(@RequestBody @Validated(value = Edit.class) DictionaryItemDTO dictionaryItem) {

		return R.ok(resourceDictionaryItemAdminClient.updateDictionaryItem(dictionaryItem));
	}

	/**
	 * 删除字典项表
	 * @param dictionaryItemIds
	 * @return
	 */
	@DeleteMapping
	@ApiOperation(value = "删除字典项表", notes = "删除字典项表")
	@SupplySysLog(value = "删除字典项表",operationType = OperationTypeEnum.DELETE)
	public R<Boolean> remove(@RequestBody @Validated List<Long> dictionaryItemIds) {

		return R.ok(resourceDictionaryItemAdminClient.removeDictionaryItemByIds(dictionaryItemIds));
	}

	/**
	 * 查询字典项详情
	 * @param dictionaryId
	 * @return
	 */
	@GetMapping("/getDictionaryItem")
	@ApiOperation(value = "查询字典项详情", notes = "查询字典项详情")
	@SupplySysLog(value = "查询字典项详情",operationType = OperationTypeEnum.SELECT)
	public R<DictionaryVO> getDictionaryItem(@RequestParam("dictionaryId") Long dictionaryId) {

		return R.ok(resourceDictionaryItemAdminClient.getDictionaryItemByDictionaryId(dictionaryId));
	}
}
